<template>
  <div>
    <h1>天气</h1>
    <button @click="getWeather">获取天气</button>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "AreaWeather",
  methods: {
    // 跳转主页
    goTheIndex() {
      this.$router.push("/theIndex");
    },
    getUserAccount() {
      return axios.get("/user/12345");
    },
    getUserPermissions() {
      return axios.get("/user/12345/permissions");
    },
    getWeather() {
      axios({
        url: "/week",
        baseURL: "https://v0.yiketianqi.com/free",
        params: {
          appid: "29277967",
          appsecret: "z5a5828R",
          unescape: 1,
          city: "南京",
        },
      })
        .then((response) => {
          console.log(response.data);
        })
        .catch((error) => {
          console.error(error);
        });
      /* axios
      .get("http://146.56.207.108:3000/Handler/UserHandler?action=quit", {
        // params: {
        //   name: "John Doe",
        //   email: "john.doe@example.com",
        // },
      })
      .then((response) => {
        console.log(response.data);
      })
      .catch((error) => {
        console.error(error);
      }); */
      // 执行多个并发请求
      /* axios
      .all([this.getUserAccount(), this.getUserPermissions()])
      .then(
        axios.spread(function (acct, perms) {
          // 两个请求现在都执行完成
          console.log(acct, perms);
        })
      )
      .catch((error) => {
        console.error(error);
      }); */
    },
  },
};
</script>
